#!/bin/bash

# Android rom update shell(update fully) of Sony Xperia XZ1 Dual G8342.
# Please put this file into the sub directory.
#   e.g: [Your android source code root directory]/[sub directory named 'shell']/sony_poplar_dsds_deploy_shell
# 
# You should change directory and execute some command to update dependency projects.
#   e.g: 
#       cd [Your android source code root directory]/[sub directory named 'shell']/sony_poplar_dsds_deploy_shell
#       sh sony_poplar_dsds_update_fully.sh
#
# create by: SteveJrong
# version: 1.0

ROOT_PATH=
getRootPath(){
	ORIGINAL_PATH=$(pwd)
	SUB_PATH=${ORIGINAL_PATH%/*}
	ROOT_PATH=${SUB_PATH%/*}
}
getRootPath

VENDOR_NAME=sony
DEVICE_ROOT_PATH=$ROOT_PATH/device
KERNEL_ROOT_PATH=$ROOT_PATH/kernel
VENDOR_ROOT_PATH=$ROOT_PATH/vendor

# android device
ANDROID_DEVICE_SONY_POPLAR_DSDS_URL=https://gitee.com/sony_xperia_xz1/android_device_sony_poplar_dsds.git
ANDROID_DEVICE_SONY_POPLAR_DSDS_BRANCH_NAME=android-12.1
ANDROID_DEVICE_SONY_POPLAR_DSDS_TRULY_PROJECT_NAME=poplar_dsds
ANDROID_DEVICE_SONY_POPLAR_DSDS_PROJECT_PATH=$DEVICE_ROOT_PATH/$VENDOR_NAME/$ANDROID_DEVICE_SONY_POPLAR_DSDS_TRULY_PROJECT_NAME # device/sony/poplar_dsds

ANDROID_DEVICE_SONY_YOSHINO_COMMON_URL=https://gitee.com/sony_xperia_xz1/android_device_sony_yoshino-common.git
ANDROID_DEVICE_SONY_YOSHINO_COMMON_BRANCH_NAME=android-12.1
ANDROID_DEVICE_SONY_YOSHINO_COMMON_TRULY_PROJECT_NAME=yoshino-common
ANDROID_DEVICE_SONY_YOSHINO_COMMON_PROJECT_PATH=$DEVICE_ROOT_PATH/$VENDOR_NAME/$ANDROID_DEVICE_SONY_YOSHINO_COMMON_TRULY_PROJECT_NAME # device/sony/yoshino-common

# android kernel
ANDROID_KERNEL_SONY_MSM8998_URL=https://gitee.com/sony_xperia_xz1/android_kernel_sony_msm8998.git
ANDROID_KERNEL_SONY_MSM8998_BRANCH_NAME=android-12.1
ANDROID_KERNEL_SONY_MSM8998_TRULY_PROJECT_NAME=msm8998
ANDROID_KERNEL_SONY_MSM8998_PROJECT_PATH=$KERNEL_ROOT_PATH/$VENDOR_NAME/$ANDROID_KERNEL_SONY_MSM8998_TRULY_PROJECT_NAME # kernel/sony/msm8998

# android vendor
ANDROID_VENDOR_SONY_POPLAR_DSDS_URL=https://gitee.com/sony_xperia_xz1/android_vendor_sony_poplar_dsds.git
ANDROID_VENDOR_SONY_POPLAR_DSDS_BRANCH_NAME=android-12.1
ANDROID_VENDOR_SONY_POPLAR_DSDS_TRULY_PROJECT_NAME=poplar_dsds
ANDROID_VENDOR_SONY_POPLAR_DSDS_PROJECT_PATH=$VENDOR_ROOT_PATH/$VENDOR_NAME/$ANDROID_VENDOR_SONY_POPLAR_DSDS_TRULY_PROJECT_NAME # vendor/sony/poplar_dsds

ANDROID_VENDOR_SONY_YOSHINO_COMMON_URL=https://gitee.com/sony_xperia_xz1/android_vendor_sony_yoshino-common.git
ANDROID_VENDOR_SONY_YOSHINO_COMMON_BRANCH_NAME=android-12.1
ANDROID_VENDOR_SONY_YOSHINO_COMMON_TRULY_PROJECT_NAME=yoshino-common
ANDROID_VENDOR_SONY_YOSHINO_COMMON_PROJECT_PATH=$VENDOR_ROOT_PATH/$VENDOR_NAME/$ANDROID_VENDOR_SONY_YOSHINO_COMMON_TRULY_PROJECT_NAME # vendor/sony/yoshino-common

# Update code
echo -e "··············· Preparing to update the code.\n"
## android device
echo -e "··············· Preparing to update the android device code.\n"

cd $ANDROID_DEVICE_SONY_POPLAR_DSDS_PROJECT_PATH
git fetch --all && git reset --hard origin/$ANDROID_DEVICE_SONY_POPLAR_DSDS_BRANCH_NAME && git pull
echo -e "··············· Done!\n"

cd $ANDROID_DEVICE_SONY_YOSHINO_COMMON_PROJECT_PATH
git fetch --all && git reset --hard origin/$ANDROID_DEVICE_SONY_YOSHINO_COMMON_BRANCH_NAME && git pull
echo -e "··············· Done!\n"

# android kernel
echo -e "··············· Preparing to update the android kernel code.\n"

cd $ANDROID_KERNEL_SONY_MSM8998_PROJECT_PATH
git fetch --all && git reset --hard origin/$ANDROID_KERNEL_SONY_MSM8998_BRANCH_NAME && git pull
echo -e "··············· Done!\n"

# android vendor
echo -e "··············· Preparing to update the android vendor code.\n"

cd $ANDROID_VENDOR_SONY_POPLAR_DSDS_PROJECT_PATH
git fetch --all && git reset --hard origin/$ANDROID_VENDOR_SONY_POPLAR_DSDS_BRANCH_NAME && git pull
echo -e "··············· Done!\n"

cd $ANDROID_VENDOR_SONY_YOSHINO_COMMON_PROJECT_PATH
git fetch --all && git reset --hard origin/$ANDROID_VENDOR_SONY_YOSHINO_COMMON_BRANCH_NAME && git pull
echo -e "··············· Done!\n"

echo -e "··············· All Done √ \n"